<template>
  <BaseDialog  :loading="loading" destroy-on-close @confirm="confirm" @close="close" confirmText="确定" v-model="isShow" title="选择表">
      <el-input v-model="schemaName">
        <template #append>
          <el-button type="primary"  >查询</el-button>
        </template>
      </el-input>
      <el-radio v-model="tableName" v-for="item in data"  :label="item">{{item}}</el-radio>
  </BaseDialog>
</template>

<script lang="ts" setup>
import {ref} from "vue";
import {listTableName} from "/@/api/generator/DatabaseApi";
import {ElMessage} from "element-plus";
import {insertTableInfo} from "/@/api/generator/TableInfoApi";
const isShow = ref(false)
const loading = ref(false)
const schemaName = ref('public')
const tableName = ref('')
const data = ref<string[]>([])
const emit = defineEmits(["load"])
const init = async() => {
  isShow.value = true
  loading.value = true
  let res = await listTableName(schemaName.value,()=>{
    loading.value = false
  })
  data.value = res
}
const confirm = async () => {
  if(!tableName.value){
    ElMessage.warning("请选择一张表")
  }
  loading.value = true
  await insertTableInfo(tableName.value,()=>{
    loading.value = false
  })
  emit("load")
  close()
}
const close = () => {
  schemaName.value = 'public'
  tableName.value = ''
  isShow.value = false
}
defineExpose({init})
</script>

<style scoped>

</style>